/*
 * @Descripttion:
 * @version:
 * @Author: zhaoxiaodong
 * @Date: 2020-09-01 10:08:02
 * @LastEditors  : 彭浩
 * @LastEditTime : 2021-02-01 10:04:16
 */
import Vue from "vue";
import VueRouter from "vue-router";
import axios from "axios";
import Login from "../views/login";
import Main from "../views/main/index.vue";
import store from "../store";
import page404 from "@/components/errorPage/404.vue";
import page401 from "@/components/errorPage/401.vue";
import blankPage from "@/components/errorPage/blankPage.vue";
import microAppStart from "../core/app-start";
Vue.use(VueRouter);
const routes = [
    {
        path: "*",
        component: page404,
    },
    {
        path: "/error",
        redirect: "/401",
    },
    {
        path: "/401",
        component: page401,
    },
    {
        path: "/blank",
        component: blankPage,
    },
    {
        path: "",
        redirect: "/workbench",
    },
];
if (process.env.NODE_ENV === "development")
    routes.push({
        path: "/login",
        component: Login,
    });
const router = new VueRouter({
    mode: "hash",
    routes,
});
router.beforeEach((to, from, next) => {
    if (
        to.path === "/library/login" ||
        to.path === "/workbench/login" ||
        to.path === "/application/login" ||
        to.path === "/space/login" ||
        to.path === "/tool/login" ||
        to.path === "/login" ||
        to.path === "/401" ||
        to.path === "/404" ||
        to.path === "/blank"
    ) {
        next();
        return;
    }
    if (store.state.user.userInfo && store.state.user.userInfo.id) {
        next();
        // //验证登陆并启动微应用
        if(!window.hasMicroAppStart){
            microAppStart();
        }
        return;
    }
    window.hasPostPreLoginUser = true;
    axios(`/designgateway/designSpace/spaceFeign/preLoginUser`).then(res => {
        store.commit("user/SET_USERINFO", res.data.data);
        next();
        // //验证登陆并启动微应用
        if(!window.hasMicroAppStart){
            microAppStart();
        }
    });
});
export default router;
